package com.sgb.kjwl.view.widget;

import android.content.Context;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.AddGoodsItemEntity;
import com.sgb.kjwl.view.ui.adapter.self.publish.SelecteUnitAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;

import java.util.List;


public class SelecteUnitPopWindow extends BasePopWindow {

    private TextView okView;
    private TextView resetView;
    private EditText etSearch;
    private RecyclerView rvUnit;

    private int resultPosition;

    private SelecteUnitAdapter selecteUnitAdapter;

    public SelecteUnitPopWindow(Context context) {
        super(context, DIR_DOWN_UP);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_selecte_unit;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        etSearch = holder.getPop().findViewById(R.id.et_search);
        rvUnit = holder.getPop().findViewById(R.id.rv_unit);
        okView = holder.getPop().findViewById(R.id.ok_view);
        resetView = holder.getPop().findViewById(R.id.reset_view);

        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        //设置布局管理器
        rvUnit.setLayoutManager(layoutManager);
        //设置为垂直布局，这也是默认的
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        //设置Adapter
        selecteUnitAdapter = new SelecteUnitAdapter(mContext);

        okView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dissMiss();
                if (onResultClick != null) {
                    onResultClick.result(resultPosition,resultPosition,null);
                }
            }
        });

        resetView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        selecteUnitAdapter.setOnItemClickListener(new SelecteUnitAdapter.ItemClickListener() {
            @Override
            public void onItemClick(int position) {
                resultPosition = position;
            }
        });
    }

    public void setDatas(List<AddGoodsItemEntity> datas) {
        selecteUnitAdapter.setDatas(datas);
        rvUnit.setAdapter(selecteUnitAdapter);
    }

}
